<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<%
	String path = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath()
			+ "/";
	request.setAttribute("path", path);
%>
<base href="<%=path%>"></base>
<title>线路管理</title>
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui/themes/icon.css">
<script type="text/javascript" src="jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui/jquery.easyui.min.js"></script>
</head>
<body>
	<!-- datagrid 显示数据 -->
	<table id="dg" style="width: 1300px; height: 250px"
		data-options="rownumbers:true,singleSelect:true,pagination:true,method:'get'">
		<thead>
			<tr>
				<th data-options="field:'linecode',width:150">线路编号</th>
				<th data-options="field:'linename',width:150">线路名称</th>
				<th data-options="field:'startpolecode',width:150">起始杆号</th>
				<th data-options="field:'endpolecode',width:150">终止杆号</th>
				<th data-options="field:'towerbasenum',width:150">基塔数</th>
				
				<th
					data-options="field:'runningstatusname',width:150,align:'right'">运行状态</th>
				<th
					data-options="field:'isstart',width:150,align:'right',formatter:changestate">启用状态</th>
				<th data-options="field:'op',width:250,align:'center',formatter:op">操作</th>
			</tr>
		</thead>
	</table>
	<!-- 辅助的小按钮 -->
	<div id="toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="addLine()">New Line</a> 
			 路线编号: <input id="linecc" class="easyui-combobox" name="dept"
			width="100px" data-options="valueField:'key',textField:'value'"
			panelHeight='auto'> 
			
			路线状态: <input id="runStatuscc"
			class="easyui-combobox" name="dept" width="100px"
			data-options="valueField:'key',textField:'value'" panelHeight='auto'>
		<input type="button" value="查询" onclick="search()">
	</div>

	<script type="text/javascript">
		//新增
		function addLine(){
			window.location='line/addGetLine';
		}
		function updateLine(id){
			window.location='line/UpdateGetLine?psLine.id='+id;
		}
		//对停用、修改、删除操作格式化
		function op(val, row) {
			var id = row.id;
			var s;
			if(row.isstart==-1){
				s='停用';
			}else{
				s='启用';
			}
			return "<a href='javascript:void(0)' onclick='toggleLine("
					+ id
					+ ")'>"+s+"|</a><a href='javascript:void(0)' onclick='updateLine("
					+ id
					+ ")'>修改|</a><a href='javascript:void(0)' onclick='deleteLine("
					+ id + ")'>删除|</a>";
		}
		//停用/启用杆塔
		function toggleLine(id) {
			$.ajax({
				url : 'line/toggleLine',
				data : {
					'psLine.id' : id
				},
				dataType : 'json',
				success : function(data) {
					showMesage(data.message);
					$('#dg').datagrid('reload');
				}
			});
		}
		function showMesage(msg){
			$.messager.show({
				title:'执行结果',
				msg:msg,
				showType:'show'
			});
		}
		function deleteLine(id) {
			$.ajax({
				url : 'line/deleteLine',
				data : {
					'psLine.id' : id
				},
				dataType : 'json',
				success : function(data) {
					showMesage(data.message);
					$('#dg').datagrid('reload');
				}
			});
		}
		function changestate(val, row) {
			if (row.isstart == true) {
				return "启动";
			} else {
				return "停用";
			}
		}
		//查询
		function search() {
			var linecode = $('#linecc').combobox('getValue');
			var runstatus = $('#runStatuscc').combobox('getValue');
			$('#dg').datagrid('reload', {
				'psLine.linecode' : linecode,
				'psLine.runningstatus' : runstatus

			});
		}
		//初始化
		$(function() {
			$('#dg').datagrid({
				toolbar : '#toolbar',
				url : 'line/showLine'
			});
			$('#runStatuscc').combobox({url:'line/findLineState'});
		})
	</script>
</body>
</html>